/*
Copyright (c) 2008, Daniel Guerrero Martínez
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
	-Redistributions of source code must retain the above copyright notice, this
	list of conditions and the following disclaimer.
	-Redistributions in binary form must reproduce the above copyright notice,
	this list of conditions and the following disclaimer in the documentation
	and/or other materials provided with the distribution.
	-Neither the name of the <ORGANIZATION> nor the names of its contributors may
	be used to endorse or promote products derived from this software without
	specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
 */

package Imagenes;

import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JColorChooser;


public class nuevo_lienzo extends javax.swing.JDialog {


    public nuevo_lienzo(java.awt.Frame parent, boolean modal,javax.swing.JDesktopPane D, BarraHerramientas H) {
        super(parent, modal);
        initComponents();
        padre = D;
        her = H;
        P_color.setBackground(Color.white);
        this.setLocation(400, 400);
    }


    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        L_nuevo = new javax.swing.JLabel();
        B_alto = new javax.swing.JSpinner();
        B_ancho = new javax.swing.JSpinner();
        B_aceptar = new javax.swing.JButton();
        B_cancelar = new javax.swing.JButton();
        E_alto = new javax.swing.JLabel();
        E_ancho = new javax.swing.JLabel();
        E_color = new javax.swing.JLabel();
        P_color = new javax.swing.JPanel();

        FormListener formListener = new FormListener();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Nuevo lienzo");
        setMinimumSize(new java.awt.Dimension(400, 200));
        setResizable(false);
        getContentPane().setLayout(null);

        L_nuevo.setText("Nuevo Lienzo");
        getContentPane().add(L_nuevo);
        L_nuevo.setBounds(10, 10, 240, 14);

        B_alto.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(100), null, null, Integer.valueOf(1)));
        getContentPane().add(B_alto);
        B_alto.setBounds(100, 40, 80, 20);

        B_ancho.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(100), null, null, Integer.valueOf(1)));
        getContentPane().add(B_ancho);
        B_ancho.setBounds(100, 80, 80, 20);

        B_aceptar.setText("Nuevo");
        B_aceptar.addActionListener(formListener);
        getContentPane().add(B_aceptar);
        B_aceptar.setBounds(150, 130, 90, 23);

        B_cancelar.setText("Cancelar");
        B_cancelar.addActionListener(formListener);
        getContentPane().add(B_cancelar);
        B_cancelar.setBounds(260, 130, 100, 23);

        E_alto.setText("Alto:");
        getContentPane().add(E_alto);
        E_alto.setBounds(60, 40, 40, 20);

        E_ancho.setText("Ancho:");
        getContentPane().add(E_ancho);
        E_ancho.setBounds(60, 80, 40, 20);

        E_color.setText("Color de fondo");
        getContentPane().add(E_color);
        E_color.setBounds(210, 30, 130, 20);

        P_color.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        P_color.addMouseListener(formListener);

        javax.swing.GroupLayout P_colorLayout = new javax.swing.GroupLayout(P_color);
        P_color.setLayout(P_colorLayout);
        P_colorLayout.setHorizontalGroup(
            P_colorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 146, Short.MAX_VALUE)
        );
        P_colorLayout.setVerticalGroup(
            P_colorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 46, Short.MAX_VALUE)
        );

        getContentPane().add(P_color);
        P_color.setBounds(210, 50, 150, 50);

        pack();
    }

    // Code for dispatching events from components to event handlers.

    private class FormListener implements java.awt.event.ActionListener, java.awt.event.MouseListener {
        FormListener() {}
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            if (evt.getSource() == B_aceptar) {
                nuevo_lienzo.this.crear_lienzo(evt);
            }
            else if (evt.getSource() == B_cancelar) {
                nuevo_lienzo.this.Cancelar_lienzo(evt);
            }
        }

        public void mouseClicked(java.awt.event.MouseEvent evt) {
            if (evt.getSource() == P_color) {
                nuevo_lienzo.this.cambiar_color(evt);
            }
        }

        public void mouseEntered(java.awt.event.MouseEvent evt) {
        }

        public void mouseExited(java.awt.event.MouseEvent evt) {
        }

        public void mousePressed(java.awt.event.MouseEvent evt) {
        }

        public void mouseReleased(java.awt.event.MouseEvent evt) {
        }
    }// </editor-fold>//GEN-END:initComponents

    private void crear_lienzo(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_crear_lienzo
        LienzoInterno lin = new LienzoInterno(her,new Dimension(((Integer)B_ancho.getValue()),((Integer)B_alto.getValue())),P_color.getBackground());
        padre.add(lin);
        this.setVisible(false);
}//GEN-LAST:event_crear_lienzo

    private void cambiar_color(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cambiar_color
        P_color.setBackground( JColorChooser.showDialog(this, "seleccion color", P_color.getBackground()));
        if(P_color.getBackground() == null)
            P_color.setBackground(Color.white);
    }//GEN-LAST:event_cambiar_color

    private void Cancelar_lienzo(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Cancelar_lienzo
        this.setVisible(false);
    }//GEN-LAST:event_Cancelar_lienzo


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton B_aceptar;
    private javax.swing.JSpinner B_alto;
    private javax.swing.JSpinner B_ancho;
    private javax.swing.JButton B_cancelar;
    private javax.swing.JLabel E_alto;
    private javax.swing.JLabel E_ancho;
    private javax.swing.JLabel E_color;
    private javax.swing.JLabel L_nuevo;
    private javax.swing.JPanel P_color;
    // End of variables declaration//GEN-END:variables
     javax.swing.JDesktopPane padre;
     BarraHerramientas her;
}
